import { $get, $post } from './utils/request'
import tableApi from '@/api/table'
import orgApi from '@/api/org'
import request from '@/api/utils/request.js'

const config = {
    ...tableApi,
    ...orgApi
}

/**
 * 
 * @param {} funcName 
 * @param {*} data 
 * @param {*} isCancel 
 * @param {*} token 
 * @returns 
 */
const req = (funcName, data, isCancel = true, token) => {
    if(data){
        if(config[funcName].url.includes('{')){
            let url=config[funcName].url.replace(/\{([\d\w_-]+)\}/g, (word, $1) => {
                var res = data[$1]
                delete data[$1]
                return res
            })
            return request({
                url: url,
                method: config[funcName].method
            })
        }else{
            return request({
                url: config[funcName].url,
                method: 'post',
                data: data
            })  
        }
        
    }else{
        return request({
            url: config[funcName].url,
            method: config[funcName].method
        })  
    } 
}
export default req